from flask_restplus import Resource, Namespace, fields, marshal, reqparse, Model

base_model = Model('base_model', {
    'id': fields.Integer(description='编号'),
    'notes': fields.String(description='备注'),
    'is_active': fields.Boolean(description='启用状态'),
    "create_datetime": fields.DateTime(description='创建时间'),
    "update_datetime": fields.DateTime(description='更新时间'),
})

# ---------- 商品 ----------
order_sku_model = base_model.inherit('order_sku_model', {
    "sku_id": fields.Integer(),
    "name": fields.String(description='名称'),
    "num": fields.Float(),
    "notes": fields.String()
})

purchase_sale_sku_model = order_sku_model.inherit('sale_purchase_sku_model', {
    "price": fields.Float(),
    "discount": fields.Float(),
})

purchase_order_sku_model = purchase_sale_sku_model.inherit('purchase_sku_model', {})
sale_order_sku_model = purchase_sale_sku_model.inherit('purchase_sku_model', {})
check_order_sku_model = order_sku_model.inherit('purchase_sku_model', {})

# ---------- 单据 ----------
order_model = base_model.inherit('purchase_order_model', {
    "order_sn": fields.String(),
    "date": fields.DateTime(),
    "status": fields.Integer(),
    "draft_status": fields.Integer(),
})

purchase_sale_order_model = base_model.inherit('order_model', {
    "customer_id": fields.Integer(),
    "warehouse_id": fields.Integer(),
    "account_id": fields.Integer(),
    "second_account_id": fields.Integer(),
    "tracking_number": fields.String(),
    "is_make": fields.Boolean(),
    "bill_info": fields.String(),
})

purchase_order_model = purchase_sale_order_model.inherit('purchase_order_model', {
    "payment": fields.Float(),
    "second_payment": fields.Float(),
    "order_skus": fields.Nested(purchase_order_sku_model)
})
sale_order_model = purchase_sale_order_model.inherit('sale_order_model', {
    "income": fields.Float(),
    "second_income": fields.Float(),
    "order_skus": fields.Nested(sale_order_sku_model)
})

check_order_model = base_model.inherit('check_order_model', {
    "warehouse_id": fields.Integer(),
    "order_skus": fields.Nested(check_order_sku_model)
})
